package com.qiang.test16;

import java.util.concurrent.*;

public class Demo06 {
    /*public static void main(String[] args) throws InterruptedException {

        //1,创建一个默认的线程池对象.池子中默认是空的.默认最多可以容纳int类型的最大值.
        ExecutorService executorService = Executors.newCachedThreadPool();
        //Executors --- 可以帮助我们创建线程池对象
        //ExecutorService --- 可以帮助我们控制线程池

        *//*executorService.submit(()->{
            System.out.println(Thread.currentThread().getName() + "在执行了");
        });*//*
        executorService.submit(()->{});

        //Thread.sleep(2000);

        executorService.submit(()->{
            System.out.println(Thread.currentThread().getName() + "在执行了");
        });

        executorService.shutdown();
    }*/
    public static void main(String[] args) {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                2,
                5,
                2,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

        //提交线程
        /*pool.submit(new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "在执行了");
            }
        }));*/
        /*pool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "在执行了");
            }
        });*/

        //pool.submit(new MyRunnable());
        pool.submit(new MyThread());
        pool.submit(new MyThread());

        pool.shutdown();
    }
}
